//工作时长
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int year , month , day , h , m , s;
vector<int>days = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
vector<int>v;
//2022-01-01 00:00:00
int main()
{
    while(scanf("%d-%d-%d %d:%d:%d", &year, &month, &day, &h, &m, &s) == 6)
    {
        int sum = 0;
        for(int i = 1;i < month;i ++)
        {
            sum += days[i];
        }
        sum += day;
        sum = sum * 24 + h;
        sum = sum * 60 + m;
        sum = sum * 60 + s;
        v.push_back(sum);
    
    }

    sort(v.begin() , v.end());

    int ans = 0;
    for(int i = 0;i < v.size();i += 2)
    {
        ans += v[i + 1] - v[i];
    }
    cout << ans << endl;
    return 0;
}